package org.pz.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RefreshScope
@RestController
public class TestController {

    @Value("${dog.age}")
    private String age;

    @Autowired
    private ApplicationContext context;

    @RequestMapping("/test")
    public String test() {

        System.out.println( "从容器中获取配置信息 name：" +  context.getEnvironment().getProperty("dog.name"));

        System.out.println( "使用 @Value 获取配置信息 age : " + age);

        return age;
    }

}
